package com.chihuo.resource;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import com.chihuo.bussiness.AllDomain;
import com.chihuo.dao.CategoryDao;
import com.chihuo.dao.DeskDao;
import com.chihuo.dao.RecipeDao;

@Path("/all")
public class AllDomainResource {
	@Context
	UriInfo uriInfo;
	@Context
	Request request;

	@GET
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public AllDomain getAllOfflineData() {
		AllDomain all = new AllDomain(new CategoryDao().findAll(),
				new RecipeDao().findAll(), new DeskDao().findAll(), new Date());
		return all;
	}

	@Path("{date}")
	@GET
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public Response getIncrement(@PathParam("date") String dateStr) {

		try {
			Date date = MyConstants.dateFormat.parse(dateStr);
			
			return Response.status(Response.Status.OK).entity("").build();
		} catch (ParseException e) {
			return Response.status(Response.Status.BAD_REQUEST)
					.entity("日期参数错误").type(MediaType.TEXT_PLAIN).build();
		}
	}

}
